<?php
/**
 * WechatExt.class.php
 * 微信扩展类
 *
 * @author  王中艺
 * @date    2016-09-22
 */
namespace Wechat\Util;

class WechatExt extends Wechat {
    private static $self;

    /**
     * 单例模式创建
     * @return object 对象自身
     */
    static function getInstance(){
        if(!self::$self){
            self::$self     = new self(array(
                'appid' => C('wechat.app_id'),
                'appsecret' => C('wechat.secret'),
                'token' => C('wechat.token')
            ));
        }

        return self::$self;
    }

    function __destruct(){
        if($this->errCode != 0){
            write_log(
                './Log/wechat_error.log', 
                'wechat request', 
                sprintf("errCode: %d\t errMsg:%s \tappId:%s", $this->errCode, $this->errMsg, $this->appid)
            );
        }
        if($this->errCode == 40001){
            S('wechat_access_token'.$this->appid, null);
        }
    }
}